import time
import datetime

"""
    TimestampCon:时间戳
    StructureCon:时间元组
    DatetimeCon:世界结构
    StrCon:字符串

    con_time:转换时间
"""


class TimestampCon(object):

    def __init__(self, time_timestamp):
        self.time_now = time_timestamp

    def con_timestamp(self):
        return self.time_now

    def con_structure(self):
        return time.localtime(self.time_now)

    def con_datetime(self):
        return datetime.datetime.fromtimestamp(self.time_now)

    def con_str(self):
        return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.time_now))


class StructureCon(object):

    def __init__(self, time_structure):
        self.time_now = time_structure
        self.time_timestamp = time.mktime(self.time_now)

    def con_timestamp(self):
        return self.time_timestamp

    def con_structure(self):
        return self.time_now

    def con_datetime(self):
        return datetime.datetime.fromtimestamp(self.time_timestamp)

    def con_str(self):
        return time.strftime("%Y-%m-%d %H:%M:%S", self.time_now)


class DatetimeCon(object):

    def __init__(self, time_datetime):
        self.time_now = time_datetime

    def con_timestamp(self):
        return self.time_now.timestamp()

    def con_structure(self):
        return self.time_now.timetuple()

    def con_datetime(self):
        return self.time_now

    def con_str(self):
        return self.time_now.strftime("%Y-%m-%d %H:%M:%S")


class StrCon(object):

    def __init__(self, time_datetime):
        self.time_now = time_datetime
        self.time_structure = time.strptime(self.time_now, "%Y-%m-%d %H:%M:%S")

    def con_timestamp(self):
        return time.mktime(self.time_structure)

    def con_structure(self):
        return self.time_structure

    def con_datetime(self):
        return datetime.datetime.strptime(self.time_now, "%Y-%m-%d %H:%M:%S")

    def con_str(self):
        return self.time_now


def con_time(my_time):
    the_type = type(my_time)
    if the_type == float or the_type == int:
        time_class = TimestampCon(my_time)
    elif the_type == time.struct_time:
        time_class = StructureCon(my_time)
    elif the_type == datetime.datetime:
        time_class = DatetimeCon(my_time)
    elif the_type == str:
        time_class = StrCon(my_time)
    else:
        raise Exception("Type error")

    return [time_class.con_timestamp(), time_class.con_structure(), time_class.con_datetime(),
            time_class.con_str()]


if __name__ == "__main__":
    ts = time.time()
    st = time.localtime()
    dt = datetime.datetime(2018, 10, 1, 22, 30, 00, 999999)
    time_str = "2015-2-3 12:30:25"

    print(con_time(time_str)[0])
